set(target_name ql_qlibpy)

add_library(${target_name} SHARED qlib_python.cpp)

if (MSVC)
    target_compile_options(${target_name} PRIVATE /bigobj)
endif()

message("PYTHONHOME = $ENV{PYTHONHOME}")

# 附加包含路径
target_include_directories(${target_name} PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${VCPKG_SDK}/include
    ${VCPKG_SDK}/include/python3.11
    ${VCPKG_SDK}/include/ql
    # $ENV{PYTHONHOME}/include
)

# # 附加库
target_link_libraries(${target_name} PRIVATE ${VCPKG_SDK}/lib/python311.lib)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(${target_name} PRIVATE ${VCPKG_SDK}/debug/lib/ql_qlib.lib)
    target_link_libraries(${target_name} PRIVATE ${VCPKG_SDK}/debug/lib/python311_d.lib)
else()
    target_link_libraries(${target_name} PRIVATE ${VCPKG_SDK}/lib/ql_qlib.lib)
endif()

# 后缀名改成pyd能够被python引用
set_target_properties(${target_name} PROPERTIES SUFFIX ".pyd")

# 安装头文件
file(GLOB_RECURSE INCLUDE_FILES ./*.h)
install(FILES ${INCLUDE_FILES} DESTINATION include/ql/qlib/python)

# 安装静态库
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    install(TARGETS ql_qlibpy
        RUNTIME DESTINATION debug/bin  # DLL 文件作为运行时文件，安装到 bin 目录
        LIBRARY DESTINATION debug/lib  # 对于 Windows 系统，此设置通常与 RUNTIME 配合使用
        ARCHIVE DESTINATION debug/lib  # 静态库（如果有的话）安装到 lib 目录
    )  
else()
    install(TARGETS ql_qlibpy
        RUNTIME DESTINATION bin  # DLL 文件作为运行时文件，安装到 bin 目录
        LIBRARY DESTINATION lib  # 对于 Windows 系统，此设置通常与 RUNTIME 配合使用
        ARCHIVE DESTINATION lib  # 静态库（如果有的话）安装到 lib 目录
    )  
endif()